﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using MINERP.BLL.InfoConfig;
using MINERP.MODEL.FoundationModel;

namespace MINERP.InfoConfig
{
    public partial class FrmWorkShop : FrmMDIChildFormTemplate
    {

        WorkShop_Info _workShop;
        
        WorkShopBLL _bll = new WorkShopBLL();
        public FrmWorkShop()
        {
            InitializeComponent();
        }

        private void FrmWorkShop_Load(object sender, EventArgs e)
        {
            try
            {
                _workShop = _bll.GetWorkShop();
                txtAddress.Text = _workShop.Address;
                txtCustomerTel.Text = _workShop.CustomerTel;
                txtEmail.Text = _workShop.Email;
                txtFinanceTel.Text = _workShop.FinanceTel;
                txtQQ.Text = _workShop.QQ;
                txtRemark.Text = _workShop.Remark;
                txtWorkShopName.Text = _workShop.WorkShopName;
                chkAutoAssignShop.Checked = _workShop.AutoAssignShop;
                chkEMByPhotoSpec.Checked =_workShop.InsertEPByPhotoSpec;
                chkControlNonexistenceTechByPriority.Checked = _workShop.ControlNonexistenceTechByPriority;
            }
            catch(Exception ex)
            {
                if(!(ex is NullReferenceException))
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Check())
            {
                try
                {
                    _workShop = new WorkShop_Info()
                    {
                        Address = txtAddress.Text,
                        CustomerTel = txtCustomerTel.Text,
                        Email = txtEmail.Text,
                        FinanceTel = txtFinanceTel.Text,
                        QQ = txtQQ.Text,
                        Remark = txtRemark.Text,
                        WorkShopName = txtWorkShopName.Text,
                        AutoAssignShop = chkAutoAssignShop.Checked,
                        ControlNonexistenceTechByPriority = chkControlNonexistenceTechByPriority.Checked,
                        InsertEPByPhotoSpec = chkEMByPhotoSpec.Checked
                    };
                    _bll.Update(_workShop);
                    MessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private bool Check()
        {
            bool flag = true;
            if (string.IsNullOrEmpty(txtWorkShopName.Text))
            {
                MessageBox.Show("请输入车间名称！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtWorkShopName.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtCustomerTel.Text))
            {
                MessageBox.Show("请输入客户电话！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtCustomerTel.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtFinanceTel.Text))
            {
                MessageBox.Show("请输入财务电话！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtFinanceTel.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtQQ.Text))
            {
                MessageBox.Show("请输入QQ号！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtQQ.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtAddress.Text))
            {
                MessageBox.Show("请输入公司地址！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtAddress.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtEmail.Text))
            {
                MessageBox.Show("请输入Email地址！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtEmail.Focus();
                return false;
            }

            return flag;
        }
    }
}
